{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-01T06:03:35.908812Z",
     "start_time": "2025-07-01T06:03:31.445413Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import datetime\n",
    "\n",
    "\n",
    "def addTimeStamp(origin_file, start: datetime.datetime, sample: int):\n",
    "    with open(origin_file, 'r') as resource_file:\n",
    "        target_file = os.path.splitext(origin_file)[0] + \"-timestamp\" + os.path.splitext(origin_file)[1]\n",
    "        with open(target_file, 'w') as new_file:\n",
    "            origin_data = resource_file.readlines()\n",
    "            my_delta = datetime.timedelta(seconds=1 / sample)\n",
    "\n",
    "            for index, line in enumerate(origin_data):\n",
    "                if str(index) == '0':  # 写入表头\n",
    "                    new_file.write(\"#\\t\" + line.strip() + \"\\t\" + \"realdate\" + \"\\t\" + \"realtime\" + \"\\n\")\n",
    "                elif str(index) == '1':  # 写入绝对时间的初始\n",
    "                    new_file.write(\"#\\t\" + line.strip() + \"\\t\" + start.strftime(\"%Y-%m-%d, %H:%M:%S\") + \"\\n\")\n",
    "                else:  # 写入计算得到的时间\n",
    "                    new_file.write(\"#\\t\" + line.strip() + \"\\t\" + str(start + my_delta * (index - 1)) + \"\\n\")\n",
    "\n",
    "\n",
    "addTimeStamp(r\"D:\\20250616 辽宁清原抽蓄热力学\\清原热力学（基础参数）\\基础参数\\2025-6-20-高水头发电.txt\",\n",
    "             datetime.datetime(2025, 6, 20, 17, 34, 8), 100)\n",
    "\n"
   ],
   "id": "9e0c5cb59b1e14ba",
   "outputs": [],
   "execution_count": 15
  },
  {
   "metadata": {
    "jupyter": {
     "is_executing": true
    },
    "ExecuteTime": {
     "start_time": "2025-07-03T07:29:30.237041Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import math\n",
    "from tkinter import filedialog\n",
    "import os\n",
    "\n",
    "\n",
    "class Calculator:\n",
    "    def __init__(self):\n",
    "        self.txt_list = []\n",
    "\n",
    "    def get_mean(self):\n",
    "        mean = sum(self.data) / len(self.data)\n",
    "        mean = mean * 0.21\n",
    "        # print(f\"{self.channel_name}: {mean}(mean)\")\n",
    "        self.info_list[1].append(mean)\n",
    "\n",
    "    def get_vpp97(self):\n",
    "        sorted_list = sorted(self.data)  # 由低到高\n",
    "        low_index = math.floor(len(sorted_list) * 0.015)\n",
    "        high_index = math.floor(len(sorted_list) * 0.985)\n",
    "        vpp97 = sorted_list[high_index] - sorted_list[low_index]\n",
    "        vpp97 = vpp97 * 0.21\n",
    "        # print(f\"{self.channel_name}: {vpp97}(vpp97)\")\n",
    "        self.info_list[2].append(vpp97)\n",
    "\n",
    "    def main(self):\n",
    "        directory = filedialog.askdirectory()\n",
    "        for filename in os.listdir(directory):\n",
    "            if filename.endswith(\".txt\"):\n",
    "                self.txt_list.append(os.path.join(directory, filename))\n",
    "        print(self.txt_list)\n",
    "\n",
    "\n",
    "my_calculator = Calculator()\n",
    "my_calculator.main()"
   ],
   "id": "1d6382f3ef7968ed",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-04T02:50:03.196983Z",
     "start_time": "2025-07-04T02:50:03.189695Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = \"gihajslkjashncoais,dxd\"\n",
    "a.strip(\",\")"
   ],
   "id": "a0b4d2a9082ee145",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'gihajslkjashncoais,dxd'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-05T17:00:59.953686Z",
     "start_time": "2025-07-05T17:00:36.087859Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import tkinter.ttk\n",
    "\n",
    "a = tkinter.Tk()\n",
    "m = tkinter.Menu(a)\n",
    "m.add_command(label='保存', command=my_calculator.main)\n",
    "b = tkinter.ttk.Menubutton(a, text='文件', menu=m)\n",
    "b.pack()\n",
    "a.mainloop()"
   ],
   "id": "bd57809d2f0553b1",
   "outputs": [],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-05T19:49:59.978508Z",
     "start_time": "2025-07-05T19:49:59.973481Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import datetime\n",
    "\n",
    "a = datetime.time(23, 50, 0)\n",
    "b = datetime.time(0, 0, 0)\n",
    "\n",
    "a1 = datetime.datetime.combine(datetime.date.today(), a)\n",
    "if b > a:\n",
    "    b1 = datetime.datetime.combine(datetime.date.today(), b)\n",
    "else:\n",
    "    b1 = datetime.datetime.combine(datetime.date.today() + datetime.timedelta(days=1), b)\n",
    "(b1 - a1).seconds\n"
   ],
   "id": "ce344c38dd0e802c",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "600"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 32
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-06T02:02:21.713142Z",
     "start_time": "2025-07-06T02:02:21.706035Z"
    }
   },
   "cell_type": "code",
   "source": "\"a\".__add__(\"b\")",
   "id": "9f3a0138de68cd26",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ab'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-06T16:42:52.391839Z",
     "start_time": "2025-07-06T16:42:52.380151Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = \"1-2-3\"\n",
    "a.split(\"-\")"
   ],
   "id": "cd920861100d3d10",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1', '2', '3']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-10T00:25:06.704662Z",
     "start_time": "2025-07-10T00:24:46.761487Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import tkinter as tk\n",
    "\n",
    "root = tk.Tk()\n",
    "\n",
    "# 创建菜单栏\n",
    "menubar = tk.Menu(root)\n",
    "root.config(menu=menubar)\n",
    "\n",
    "# 创建一级菜单\n",
    "file_menu = tk.Menu(menubar, tearoff=0)\n",
    "file_menu.add_command(label='新建')\n",
    "file_menu.add_command(label='打开')\n",
    "menubar.add_cascade(label=\"文件\", menu=file_menu)\n",
    "\n",
    "# 创建二级菜单\n",
    "edit_menu = tk.Menu(file_menu, tearoff=0)\n",
    "edit_menu.add_command(label=\"剪切\")\n",
    "edit_menu.add_command(label=\"复制\")\n",
    "file_menu.add_cascade(label=\"编辑\", menu=edit_menu)\n",
    "\n",
    "# 创建三级菜单\n",
    "paste_menu = tk.Menu(edit_menu, tearoff=0)\n",
    "paste_menu.add_command(label=\"全选\")\n",
    "paste_menu.add_command(label=\"删除\")\n",
    "edit_menu.add_cascade(label='粘贴', menu=paste_menu)\n",
    "\n",
    "root.mainloop()\n"
   ],
   "id": "d00d0ce5c990857c",
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-10T01:09:18.912477Z",
     "start_time": "2025-07-10T01:09:18.154940Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import tkinter\n",
    "\n",
    "root = tkinter.Tk()\n",
    "\n",
    "a1 = tkinter.Frame(root)\n",
    "a2 = tkinter.Frame(root)\n",
    "a1.pack()\n",
    "a2.pack()\n",
    "\n",
    "a3 = tkinter.Label(a1,text='12345')\n",
    "a4 = tkinter.Label(a2,text='qwert')\n",
    "a1.pack(side=tkinter.LEFT)\n",
    "a2.grid(row=0, column=0)\n",
    "\n",
    "root.mainloop()\n"
   ],
   "id": "d000bfac55733131",
   "outputs": [
    {
     "ename": "TclError",
     "evalue": "cannot use geometry manager grid inside . which already has slaves managed by pack",
     "output_type": "error",
     "traceback": [
      "\u001B[31m---------------------------------------------------------------------------\u001B[39m",
      "\u001B[31mTclError\u001B[39m                                  Traceback (most recent call last)",
      "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[2]\u001B[39m\u001B[32m, line 13\u001B[39m\n\u001B[32m     11\u001B[39m a4 = tkinter.Label(a2,text=\u001B[33m'\u001B[39m\u001B[33mqwert\u001B[39m\u001B[33m'\u001B[39m)\n\u001B[32m     12\u001B[39m a1.pack(side=tkinter.LEFT)\n\u001B[32m---> \u001B[39m\u001B[32m13\u001B[39m \u001B[43ma2\u001B[49m\u001B[43m.\u001B[49m\u001B[43mgrid\u001B[49m\u001B[43m(\u001B[49m\u001B[43mrow\u001B[49m\u001B[43m=\u001B[49m\u001B[32;43m0\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mcolumn\u001B[49m\u001B[43m=\u001B[49m\u001B[32;43m0\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[32m     15\u001B[39m root.mainloop()\n",
      "\u001B[36mFile \u001B[39m\u001B[32m~\\miniconda3\\envs\\post-data-process\\Lib\\tkinter\\__init__.py:2580\u001B[39m, in \u001B[36mGrid.grid_configure\u001B[39m\u001B[34m(self, cnf, **kw)\u001B[39m\n\u001B[32m   2565\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mgrid_configure\u001B[39m(\u001B[38;5;28mself\u001B[39m, cnf={}, **kw):\n\u001B[32m   2566\u001B[39m \u001B[38;5;250m    \u001B[39m\u001B[33;03m\"\"\"Position a widget in the parent widget in a grid. Use as options:\u001B[39;00m\n\u001B[32m   2567\u001B[39m \u001B[33;03m    column=number - use cell identified with given column (starting with 0)\u001B[39;00m\n\u001B[32m   2568\u001B[39m \u001B[33;03m    columnspan=number - this widget will span several columns\u001B[39;00m\n\u001B[32m   (...)\u001B[39m\u001B[32m   2578\u001B[39m \u001B[33;03m                  widget stick to the cell boundary\u001B[39;00m\n\u001B[32m   2579\u001B[39m \u001B[33;03m    \"\"\"\u001B[39;00m\n\u001B[32m-> \u001B[39m\u001B[32m2580\u001B[39m     \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43mtk\u001B[49m\u001B[43m.\u001B[49m\u001B[43mcall\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m   2581\u001B[39m \u001B[43m          \u001B[49m\u001B[43m(\u001B[49m\u001B[33;43m'\u001B[39;49m\u001B[33;43mgrid\u001B[39;49m\u001B[33;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[33;43m'\u001B[39;49m\u001B[33;43mconfigure\u001B[39;49m\u001B[33;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_w\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m   2582\u001B[39m \u001B[43m          \u001B[49m\u001B[43m+\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_options\u001B[49m\u001B[43m(\u001B[49m\u001B[43mcnf\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mkw\u001B[49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m\n",
      "\u001B[31mTclError\u001B[39m: cannot use geometry manager grid inside . which already has slaves managed by pack"
     ]
    }
   ],
   "execution_count": 2
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
